package com.ruoyi.building.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.building.domain.XgStudentPartyBuilding;
import com.ruoyi.building.service.IXgStudentPartyBuildingService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生党建Controller
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/building/building")
public class XgStudentPartyBuildingController extends BaseController
{
    @Autowired
    private IXgStudentPartyBuildingService xgStudentPartyBuildingService;

    /**
     * 查询学生党建列表
     */
    @PreAuthorize("@ss.hasPermi('building:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(XgStudentPartyBuilding xgStudentPartyBuilding)
    {
        startPage();
        List<XgStudentPartyBuilding> list = xgStudentPartyBuildingService.selectXgStudentPartyBuildingList(xgStudentPartyBuilding);
        return getDataTable(list);
    }

    /**
     * 导出学生党建列表
     */
    @PreAuthorize("@ss.hasPermi('building:building:export')")
    @Log(title = "学生党建", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XgStudentPartyBuilding xgStudentPartyBuilding)
    {
        List<XgStudentPartyBuilding> list = xgStudentPartyBuildingService.selectXgStudentPartyBuildingList(xgStudentPartyBuilding);
        ExcelUtil<XgStudentPartyBuilding> util = new ExcelUtil<XgStudentPartyBuilding>(XgStudentPartyBuilding.class);
        util.exportExcel(response, list, "学生党建数据");
    }

    /**
     * 获取学生党建详细信息
     */
    @PreAuthorize("@ss.hasPermi('building:building:query')")
    @GetMapping(value = "/{stuId}")
    public AjaxResult getInfo(@PathVariable("stuId") Long stuId)
    {
        return success(xgStudentPartyBuildingService.selectXgStudentPartyBuildingByStuId(stuId));
    }

    /**
     * 新增学生党建
     */
    @PreAuthorize("@ss.hasPermi('building:building:add')")
    @Log(title = "学生党建", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XgStudentPartyBuilding xgStudentPartyBuilding)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        xgStudentPartyBuilding.setDeptId(105L);
        xgStudentPartyBuilding.setUserId(user.getUserId());
        return toAjax(xgStudentPartyBuildingService.insertXgStudentPartyBuilding(xgStudentPartyBuilding));
    }

    /**
     * 修改学生党建
     */
    @PreAuthorize("@ss.hasPermi('building:building:edit')")
    @Log(title = "学生党建", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XgStudentPartyBuilding xgStudentPartyBuilding)
    {
        return toAjax(xgStudentPartyBuildingService.updateXgStudentPartyBuilding(xgStudentPartyBuilding));
    }

    /**
     * 删除学生党建
     */
    @PreAuthorize("@ss.hasPermi('building:building:remove')")
    @Log(title = "学生党建", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stuIds}")
    public AjaxResult remove(@PathVariable Long[] stuIds)
    {
        return toAjax(xgStudentPartyBuildingService.deleteXgStudentPartyBuildingByStuIds(stuIds));
    }
}
